package com.bdqn.vueboot.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bdqn.vueboot.entity.Conference;
import com.bdqn.vueboot.entity.ConferenceRoot;
import com.bdqn.vueboot.entity.Department;
import com.bdqn.vueboot.service.ConferenceRootService;
import com.bdqn.vueboot.service.ConferenceService;
import com.bdqn.vueboot.service.DepartmentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/conferenceRoot")
@CrossOrigin
public class ConferenceRootController {
    @Resource
    ConferenceRootService conferenceRootService;
    @Resource
    ConferenceService conferenceService;
    @Resource
    DepartmentService departmentService;

    @RequestMapping("/list")
    @CrossOrigin
    public Map list(@RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
                    @RequestParam(value = "conferenceTitle", required = false, defaultValue = "") String conferenceTitle,
                    @RequestParam(value = "conferenceName", required = false, defaultValue = "") String conferencename,
                    @RequestParam(value = "meetingStatusId", required = false, defaultValue = "0") Integer meetingStatusId,
                    @RequestParam(value = "limit", required = false, defaultValue = "5") Integer limit) {

        if (conferencename.equals("查询全部")) {
            conferencename = "";
        }
        IPage<ConferenceRoot> page = conferenceRootService.findAllByConferenceListBiz(conferenceTitle, conferencename, meetingStatusId, pageIndex, limit);
        for (ConferenceRoot conferenceRoot : page.getRecords()) {
            System.out.println(conferenceRoot.getMeetingTime());
        }
        //会议室全部信息
        List<Conference> conferenceList = conferenceService.findConferenceListBiz();
        //部门表全部信息
        List<Department> departmentList = departmentService.allDepartmentListBiz();
        Map map = new HashMap();
        map.put("page", page);
        map.put("conferenceList", conferenceList);
        map.put("departmentList", departmentList);
        return map;
    }

    @PostMapping("/seva")
    @CrossOrigin
    public int seva(@RequestBody ConferenceRoot conferenceRoot) {
//        conferenceRoot.setCreationId(1l);
//        conferenceRoot.setCreationTime(LocalDateTime.now());
        int count = conferenceRootService.addConferenceRoot(conferenceRoot);
        return count;
    }

    @GetMapping("/delConferenceRoot")
    @CrossOrigin
    public int delConferenceRoot(@RequestParam(value = "odd") Long odd, @RequestParam(value = "isDele") Long isDele) {
        int count = conferenceRootService.delIsDeleByOdd(odd, isDele);
        System.out.println(count);
        return count;
    }

    @GetMapping("/audit")
    @CrossOrigin
    public int sevaAudit(@RequestParam(value = "meetingStatusId") Integer meetingStatusId, @RequestParam(value = "odd") Long odd) {
        return conferenceRootService.sevaAudit(meetingStatusId, odd);
    }


}
